<template>
  <div>
    <Review ref="review" @ok="search"></Review>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="90"
      :scrollX="1500"
      @search="onSearch"
      @header="mergeHeader"
      @admin="toAdmin"
    >
      <template slot="columns">
        <a-table-column
          v-for="column in headers"
          :key="column.code"
          :width="column.width ? column.width : 'auto'"
          :title="column.label"
        >
          <template slot-scope="text, record">{{ record[column.code] }}</template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
const writeOffTypeArr = [
  { label: '预警注销', value: 'warning' },
  { label: '主动注销', value: 'active' }
]
export default {
  data() {
    return {
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showDataCheck: true,
        showPageTitle: false
      },
      dataBtns: [
        {
          key: 'detail',
          name: '详情',
          type: 'link',
          isShow: () => true
        }
      ],
      headers: [
        { code: 1, label: '企业代码', isShow: true, sort: 0 },
        { code: 2, label: '企业名称', isShow: true, sort: 0 },
        { code: 3, label: '信用代码', isShow: true, sort: 0 },
        { code: 4, label: '企业性质', isShow: true, sort: 0 },
        { code: 5, label: '企业等级', isShow: true, sort: 0 },
        { code: 6, label: '认证日期', isShow: true, sort: 0 },
        { code: 7, label: '注销状态', isShow: true, sort: 0 },
        { code: 8, label: '注销来源', isShow: true, sort: 0 },
        { code: 9, label: '申请时间', isShow: true, sort: 0 }
      ],
      conditions: [
        {
          code: 'code',
          label: '企业代码',
          compType: '单行文本',
          defaultVal: '',
          extra: { placeholder: '请输入企业代码' }
        },
        {
          code: 'name',
          label: '企业名称',
          compType: '单行文本',
          defaultVal: '',
          extra: { placeholder: '请输入企业名称' }
        },
        {
          code: 'creditCode',
          label: '信用代码',
          compType: '单行文本',
          defaultVal: '',
          extra: { placeholder: '请输入信用代码' }
        },
        {
          code: 'verifyDate',
          label: '认证日期',
          compType: '日期',
          defaultVal: '',
          extra: { placeholder: '请选择认证日期' }
        },
        {
          code: 'writeOffOrigin',
          label: '注销来源',
          compType: '下拉选择',
          defaultVal: '',
          extra: { 下拉选项: writeOffTypeArr, placeholder: '请选择注销来源' }
        },
        {
          code: 'applyDate',
          label: '申请时间',
          compType: '日期',
          defaultVal: '',
          extra: { placeholder: '请选择申请时间' }
        }
      ]
    }
  },
  components: {
    Review: () => import('./Review.vue')
  },
  computed: {},
  methods: {
    // 获取列表
    search() {
      this.$refs.page.search()
    },
    onSearch() {
      this.$refs.page.endSearch({
        total: 2,
        list: [{ id: 1 }, { id: 2 }]
      })
    },
    mergeHeader(newHeaders) {
      if (!newHeaders) return
      this.headers = newHeaders.filter((t) => t.isShow).sort((a, b) => a.sort - b.sort)
    },
    // 操作栏
    toAdmin(data) {
      const { key, obj } = data
      if (key === 'detail') {
        this.$refs.review.open(obj, 'details')
      }
    }
  },
  created() {},
  mounted() {}
}
</script>
<style lang="less" scoped></style>
